package cn.tedu.egmvc1.controller;

import cn.tedu.egmvc1.mapper.EmployeeMapper;
import cn.tedu.egmvc1.pojo.dto.EmployeeDTO1;
import cn.tedu.egmvc1.pojo.entity.Employee;
import cn.tedu.egmvc1.pojo.vo.EmployeeVO1;
import com.fasterxml.jackson.databind.util.BeanUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class EmployeeController {
    @Autowired
    private EmployeeMapper employeeMapper;

    @RequestMapping("/emp/insert")
    @ResponseBody
    public String insert(EmployeeDTO1 employeeDTO1) {
        Employee employee = new Employee();
        BeanUtils.copyProperties(employeeDTO1, employee);
        employeeMapper.insertEmployeeDTO1(employee);
        return "员工添加成功";
    }

    @RequestMapping("/emp/select")
    @ResponseBody
    public List<EmployeeVO1> select() {
        return employeeMapper.selectEmployeeVO1();
    }

    @RequestMapping("/emp/update")
    @ResponseBody
    public String update(Employee employee) {
        employeeMapper.updateEmployee(employee);
        return "员工修改成功";
    }

    @RequestMapping("/emp/delete")
    @ResponseBody
    public String delete(Integer id) {
        employeeMapper.deleteEmployee(id);
        return "员工删除成功";
    }
}
